<template>
  <div id="right">
    <div class="edit-question">
      <questionnaire-title :title="title" :remarks="description" @changeTitle="changeQTitle"></questionnaire-title>
      <transition-group tag="div" class="container">
        <div v-for="(question, index) in questions"
             draggable="true"
             :key="question.id"
             @dragstart="handleDragStart($event, question)"
             @dragover.prevent="handleDragOver($event, question)"
             @dragenter="handleDragEnter($event, question)"
             @dragend="handleDragEnd($event, question)">
          <div v-if="qtype(question)==1">
            <radio-show
                @click="select(question)"
                :title="question.title"
                :isNess="question.isNecessary"
                :no="getno(index)"
                :options="question.options"
                :questionnaire-id="questionnaireId"
                :questions="questions.filter((item,index2)=>{
                  return index2<index&&item.type!=='completion'&&item.type!=='score'
                })"
                :question-id="question.id"
                :question="question"
                @edit="select(question)"
                @copy="copy(question)"
                @deleteQ="deleteQ(question)"
                @moveup="moveup(question)"
                @movedown="movedown(question)"
                @movetop="movetop(question)"
                @movebottom="movebottom(question)"
            >

            </radio-show>
          </div>

          <div v-if="qtype(question)==2">
            <check-box-show
                @click="select(question)"
                :title="question.title"
                :isNess="question.isNecessary"
                :no="getno(index)"
                :options="question.options"
                :questionnaire-id="questionnaireId"
                :questions="questions.filter((item,index2)=>{
                  return index2<index&&item.type!=='completion'&&item.type!=='score'
                })"
                :question-id="question.id"
                :question="question"
                @edit="select(question)"
                @copy="copy(question)"
                @deleteQ="deleteQ(question)"
                @moveup="moveup(question)"
                @movedown="movedown(question)"
                @movetop="movetop(question)"
                @movebottom="movebottom(question)"
            >
            </check-box-show>
          </div>

          <div v-if="qtype(question)==3">
            <completion-show
                @click="select(question)"
                :title="question.title"
                :isNess="question.isNecessary"
                :no="getno(index)"
                :questionnaire-id="questionnaireId"
                :questions="questions.filter((item,index2)=>{
                  return index2<index&&item.type!=='completion'&&item.type!=='score'
                })"
                :question-id="question.id"
                :question="question"
                @edit="select(question)"
                @copy="copy(question)"
                @deleteQ="deleteQ(question)"
                @moveup="moveup(question)"
                @movedown="movedown(question)"
                @movetop="movetop(question)"
                @movebottom="movebottom(question)">
            </completion-show>
          </div>

          <div v-if="qtype(question)==4">
            <star-show
                @click="select(question)"
                :title="question.title"
                :isNess="question.isNecessary"
                :no="getno(index)"
                :max="getmax(question)"
                :questionnaire-id="questionnaireId"
                :questions="questions.filter((item,index2)=>{
                  return index2<index&&item.type!=='completion'&&item.type!=='score'
                })"
                :question-id="question.id"
                :question="question"
                @edit="select(question)"
                @copy="copy(question)"
                @deleteQ="deleteQ(question)"
                @moveup="moveup(question)"
                @movedown="movedown(question)"
                @movetop="movetop(question)"
                @movebottom="movebottom(question)"
            >
            </star-show>
          </div>

          <div v-if="qtype(question)===5">
            <completion-card-show
                @click="select(question)"
                :title="question.title"
                :isNess="question.isNecessary"
                :no="getno(index)"
                :questionnaire-id="questionnaireId"
                :questions="questions.filter((item,index2)=>{
                  return index2<index&&item.type!=='completion'&&item.type!=='score'
                })"
                :question-id="question.id"
                :question="question"
                @edit="select(question)"
                @copy="copy(question)"
                @deleteQ="deleteQ(question)"
                @moveup="moveup(question)"
                @movedown="movedown(question)"
                @movetop="movetop(question)"
                @movebottom="movebottom(question)">
            </completion-card-show>
          </div>

        </div>
      </transition-group>
    </div>
    <question-edit
        :question="questions[editindex]"
        :drawer="drawer"
        @changeTitle="changeTitle"
        @changeNess="changeNess"
        @changeRandom="changeRandom"
        @finish="finish"
        @addOption="addOption"
        @deleteOption="deleteOption"
        @changeDefault="changeDefault"
        @changeText="changeText"
        @changeDes="changeDes"
        @upmove="upmove"
        @downmove="downmove"
        @addFinalOption="addFinalOption"
        @autoFill="autoFill"
        @changeGrade="changeGrade"
    >
    </question-edit>
  </div>
</template>

<script>
import QuestionnaireTitle from '../QuestionnaireTitle'
import RadioShow from '../question/radioButton/RadioShow'
import ChooseEdit from '../question/ChooseEdit'
import CompletionEdit from '../question/completion/CompletionEdit'
import CheckBoxShow from '../question/checkBox/CheckBoxShow'
import CompletionShow from '../question/completion/CompletionShow'
import QuestionEdit from '../QuestionEdit'
import StarShow from '../question/score/StarShow'
import CompletionCardEdit from './question/completion/CompletionCardEdit'
import CompletionCardShow from './question/completion/CompletionCardShow'
import axios from "axios"
import qs from "qs"
import { h } from 'vue'
import { ElMessage } from 'element-plus'

export default {
  name:'RightCreate',
  components: {
    QuestionnaireTitle,
    RadioShow,
    ChooseEdit,
    CheckBoxShow,
    CompletionShow,
    CompletionEdit,
    QuestionEdit,
    StarShow,
    CompletionCardShow,
    CompletionCardEdit
  },
  data() {
    return {
      title: '标题',
      description: '',
      dragging: null,
      drawer: false,
      questions: [
      ],
      editindex: 0,
      isAutoLabel: true,
      randomType: '',
      isAutoSubmit: false,
      begin: null,
      end: null,
      isDate: false,
      submit: 1,
    }
  },
  props: {
    // isAutoLabel: {
    //   type: Boolean,
    //   default: true,
    // },
    // isAutoSubmit: {
    //   type: Boolean,
    //   default: false,
    // },
    // randomType: {
    //   type: Boolean,
    //   default: false,
    // },
    // begin: {
    //   type: String,
    //   default: null,
    // },
    // end: {
    //   type: String,
    //   default: null,
    // },
    questionnaireId: {
      type: Number,
      default: 0,
    },

  },
  computed: {
    question() {
      return this.questions[this.editindex]
    },
  },
  mounted() {
    this.apiGetData()
    var _this = this;
    this.timer = setInterval(() => {
      if(this.submit % 60 !=0) {
        this.submit++
      }else{
        this.submit = 1
        this.apiEditQuestionnaire()
      }
    }, 1000);
  },
  destroyed() {
	  if (this.timer) {
    	clearInterval(this.timer); // 在Vue实例销毁前，清除当前日期定时器
    };
  },
  methods: {
    getdata(res) {
      return res.data.data
    },

    apiGetData() {
      let data = {
        id: localStorage.getItem('id'),
        questionnaireId: this.questionnaireId
      }
      console.log(data);
      axios.post('/api/edit/getQuestionnaire',qs.stringify(data)).then(res => {
        console.log(res.data.data);
        if(res.data.code === 0) {
          this.title = this.getdata(res)['title']

          this.description = this.getdata(res)['description']
          this.$emit('initLabel', this.getdata(res)['isAutoLabel'])
          this.$emit('initRandom', this.getdata(res)['randomType'])
          this.$emit('initSubmit', this.getdata(res)['isAutoSubmit'])
          this.$emit('initBegin', this.getdata(res)['beginDate'])
          this.$emit('initEnd', this.getdata(res)['endDate'])
          this.$emit('initDate', this.getdata(res)['isDate'])
          this.questions = this.getdata(res)['questions']
          if(this.title === '' || this.title == null) {
            this.title = '问卷标题'
            this.apiEditQuestionnaire()
          }
        }else if(res.data.code === -1){
          this.$emit('changeState')
        }
        else {
          console.log(res)
        }
      })
    },

    apileave() {
      let data = {
        questionnaireId: this.questionnaireId,
        title: this.title,
        description: this.description,
        isAutoLabel: this.isAutoLabel,
        randomType: this.randomType,
        isAutoSubmit: this.isAutoSubmit,
        beginDate: this.begin,
        endDate: this.end,
        isDate: this.isDate,  
      }
      console.log(data);
      axios.post('/api/edit/editQuestionnaire',data).then(res => {
        if(res.data.code === 0) {
          const { href } = this.$router.resolve({
              path: '/qamanage',
            });
          window.open(href,'_self')
        }else {
          console.log(res)
        }
      })
    },
    
    apiEditQuestionnaire() {
      let data = {
        questionnaireId: this.questionnaireId,
        title: this.title,
        description: this.description,
        isAutoLabel: this.isAutoLabel,
        randomType: this.randomType,
        isAutoSubmit: this.isAutoSubmit,
        beginDate: this.begin,
        endDate: this.end,
        isDate: this.isDate,
      }
      console.log(data);
      axios.post('/api/edit/editQuestionnaire',data).then(res => {
        if(res.data.code === 0) {
          ElMessage.success({
            message: '自动保存成功',
            type: 'success'
          });
        }else {
          console.log(res)
        }
      })
    },

    apiAddQuestion(type, qtype=null) {
      console.log(qtype);
      let data = {
        questionnaireId: this.questionnaireId,
        type: type,
        qtype: qtype
      }
      // window.scrollTo(0,50000);
      axios.post('/api/edit/addQuestion',qs.stringify(data)).then(res => {
        if(res.data.code === 0) {
          console.log(res);
          switch(type) {
            case 'radio':
              this.questions.push({
                id: this.getdata(res)['questionId'],
                title: '单选题',
                isNecessary: true,
                type: type,
                qtype: null,
                isRandom: false,
                options:[
                  {
                    id: null,
                    text: '选项',
                    description: '',
                    isDefault: false,
                  },
                ]})
              break;
            case 'checkbox':
              this.questions.push({
                id: this.getdata(res)['questionId'],
                title: '多选题',
                isNecessary: true,
                type: type,
                qtype: null,
                isRandom: false,
                options:[
                  {
                    id: null,
                    text: '选项',
                    description: '',
                    isDefault: false,
                  },
                ]})
              break;
            case 'completion':
              if(qtype == null) {
                this.questions.push({
                  id: this.getdata(res)['questionId'],
                  title: '填空题',
                  type: type,
                  qtype: null,
                  isNecessary: true})
              } else if (qtype === 'card') {
                this.questions.push({
                  id: this.getdata(res)['questionId'],
                  title: '获取地理位置信息',
                  type: type,
                  qtype: qtype,
                  isNecessary: true
                })
              }
              break
            case 'score':
              this.questions.push({
                id: this.getdata(res)['questionId'],
                title: '评分题',
                type: type,
                qtype: null,
                isNecessary: true,
                options:[
                  {
                    id: null,
                    score: 0,
                  },{
                    id: null,
                    score: 1,
                  },{
                    id: null,
                    score: 2,
                  },{
                    id: null,
                    score: 3,
                  },{
                    id: null,
                    score: 4,
                  },
                ]})
              break
          }
          this.editindex = this.questions.length - 1
          this.drawer = true
          console.log(this.questions);
        }else {
          console.log(res)
        }
      })
    },

    apiDeleteQuestion(questionId, type) {
      let data = {
        questionId: questionId,
        type: type
      }
      axios.post('/api/edit/deleteQuestion',qs.stringify(data)).then(res => {
        if(res.data.code === 0) {
          console.log(res)
        }else {
          console.log(res)
        }
      })
    },

    apiChangeOrder() {
      const questionIds = []
      this.questions.forEach(question => {
        questionIds.push({questionId: question.id, type: question.type})
      });
      let data = {
        questionnaireId: this.questionnaireId,
        questionIds: questionIds
      }
      console.log(data);
      // axios({
      //   url: 'api/edit/changeOrder',
      //   method: 'post',
      //   data: data,
      //   headers: {
      //     'Content-Type': 'application/json'
      //   }
      // }).then(res => {
      //   if(res.data.code == 0) {

      //   }else {
      //     console.log(res)
      //   }
      // })
      axios.post('/api/edit/changeOrder',data).then(res => {
        // axios.post('api/edit/changeOrder',JSON.stringify(data)).then(res => {
        if(res.data.code === 0) {

        }else {
          console.log(res)
        }
      })
    },

    apiEditRadio(question) {
      let data = question
      console.log(data);
      axios.post('/api/edit/editRadio',data).then(res => {
        if(res.data.code === 0) {
          this.apigetRadio(this.questions[this.editindex].id)
        }else {
          console.log(res)
        }
      })
    },

    apiEditCheckBox(question) {
      let data = question
      console.log(question);
      axios.post('/api/edit/editCheckBox',data).then(res => {
        if(res.data.code === 0) {
          this.apigetCheckBox(this.questions[this.editindex].id)
        }else {
          console.log(res)
        }
      })
    },

    apiEditCompletion(question) {
      let data = question
      axios.post('/api/edit/editCompletion',data).then(res => {
        if(res.data.code === 0) {
          this.apigetCompletion(this.questions[this.editindex].id)
        }else {
          console.log(res)
        }
      })
    },

    apiEditScore(question) {
      let data = question
      axios.post('/api/edit/editScore',data).then(res => {
        if(res.data.code === 0) {
          this.apigetScore(this.questions[this.editindex].id)
        }else {
          console.log(res)
        }
      })
    },

    apigetRadio(id) {
      let data = {
        questionId: id,
      }
      axios.post('/api/edit/getRadio',qs.stringify(data)).then(res => {
        if(res.data.code === 0) {
          this.questions.every((item,index)=>{
            if(item.id === id){
              this.questions.splice(index,1,this.getdata(res));
              return false;
            }
            return true;
          })
        }else {
          console.log(res)
        }
      })
    },

    apigetCheckBox(id) {
      let data = {
        questionId: id,
      }
      axios.post('/api/edit/getCheckBox',qs.stringify(data)).then(res => {
        if(res.data.code === 0) {
          this.questions.every((item,index)=>{
            if(item.id === id){
              this.questions.splice(index,1,this.getdata(res));
              return false;
            }
            return true;
          })
        }else {
          console.log(res)
        }
      })
    },

    apigetCompletion(id) {
      let data = {
        questionId: id,
      }
      axios.post('/api/edit/getCompletion',qs.stringify(data)).then(res => {
        if(res.data.code == 0) {
          this.questions.every((item,index)=>{
            if(item.id === id){
              this.questions.splice(index,1,this.getdata(res));
              return false;
            }
            return true;
          })
        }else {
          console.log(res)
        }
      })
    },

    apigetScore(id) {
      let data = {
        questionId: id,
      }
      axios.post('/api/edit/getScore',qs.stringify(data)).then(res => {
        if(res.data.code === 0) {
          this.questions.every((item,index)=>{
            if(item.id === id){
              this.questions.splice(index,1,this.getdata(res));
              return false;
            }
            return true;
          })
        }else {
          console.log(res)
        }
      })
    },

    changeQTitle(data) {
      this.title = data.title
      this.description = data.description
      console.log(this.title);
      if(this.title == '') {
        this.$notify({
          title: '错误',
          message: h('i', { style: 'color: teal'}, '问卷标题不能为空')
        });
        this.title = '问卷标题'
      }
      this.apiEditQuestionnaire()
    },

    // 判断问题类型
    qtype(question) {
      switch(question.type){
        case 'radio':
          return 1;
        case 'checkbox':
          return 2;
        case 'completion':
          if(question.qtype == null) return 3;
          else return 5
        case 'score':
          return 4;
      }
    },

    // 判断问题是否处于编辑状态
    editState(question) {
      return question.isSelect
    },

    // 编辑问题
    select(question) {
      for (const item of this.questions) {
        if(item!=question && item.isSelect){
          item.isSelect = false
          switch(item.type) {
            case 'radio':
              this.apiEditRadio(item)
              break
            case 'checkbox':
              this.apiEditCheckBox(item)
              break
            case 'completion':
              this.apiEditCompletion(item)
              break
            case 'score':
              this.apiEditScore(item)
              break
          }
        }
      }
      question.isSelect = true
      this.editindex = this.questions.indexOf(question)
      this.drawer = true
    },

    changeTitle(title) {
      if(title == '' || title == null) {
        this.$notify({
          title: '错误',
          message: h('i', { style: 'color: teal'}, '题目名不能为空')
        });
        switch(this.questions[this.editindex].type) {
          case 'radio':
            this.questions[this.editindex].title = '单选题'
            break
          case 'checkbox':
            this.questions[this.editindex].title = '多选题'
            break
          case 'completion':
            this.questions[this.editindex].title = '填空题'
            break
          case 'score':
            this.questions[this.editindex].title = '评分题'
            break
        }
      }else
        this.questions[this.editindex].title = title
    },

    changeGrade(max) {
      const score = this.question.options.length - 1
      if(score < max) {
        for(let i=score+1; i<=max; i++){
          this.question.options.push(
              {
                id: null,
                text: '',
                score: i,
              }
          )
        }
      }else if(score > max) {
        this.question.options.splice(max+1, score-max)
      }
      this.apiEditScore(this.question)
    },

    getno(index) {
      if(!this.isAutoLabel) {
        return 0
      }else{
        return index+1
      }
    },

    getDefault(options) {
      // options.forEach(option => {
      //   if(option.isDefault){
      //     console.log(option);
      //     return option.id
      //   }
      // });
      for(let option of options) {
        if(option.isDefault){
          console.log(option);
          return option.id
        }
      }
    },

    getDefaultList(options) {
      const checklist = [];
      options.forEach(option => {
        if(option.isDefault){
          checklist.push(option.id)
        }
      });
      return checklist
    },

    changeNess(checked) {
      this.questions[this.editindex].isNecessary = checked
    },

    changeRandom(isRandom) {
      this.question.isRandom = isRandom
    },

    finish() {
      const question = this.questions[this.editindex]
      question.isSelect = false
      this.drawer = false
      switch(question.type) {
        case 'radio':
          this.apiEditRadio(question)
          break
        case 'checkbox':
          this.apiEditCheckBox(question)
          break
        case 'completion':
          this.apiEditCompletion(question)
          break
        case 'score':
          this.apiEditScore(question)
          break
      }
    },

    addOption(index) {
      console.log(1);
      switch(this.questions[this.editindex].type){
        case 'radio':
        case 'checkbox':
          this.questions[this.editindex].options.splice(index+1,0,
              {id: null,
                text: '选项', isDefault: false , description:null})
          break
        case 'score':
          this.questions[this.editindex].options.splice(index+1,0,
              {id: null,
                text: '选项'+(index+2), score: index+2})
          break
      }

    },

    deleteOption(index){
      this.questions[this.editindex].options.splice(index,1)
    },

    changeDefault(index) {
      if(this.question.type == 'radio' && !this.question.options[index].isDefault){
        this.question.options.forEach((item,index)=>{
          item.isDefault = false
          this.question.options.splice(index,1,item)
        });
      }
      this.question.options[index].isDefault = !this.question.options[index].isDefault
    },

    changeText(data) {
      if(data.text == '' || data.text == null) {
        this.$notify({
          title: '错误',
          message: h('i', { style: 'color: teal'}, '选项名不能为空')
        });
        this.question.options[data.index].text = '选项'
      }else
        this.question.options[data.index].text = data.text
    },

    changeDes(data) {
      this.question.options[data.index].description = data.description
    },

    // changeGrade(data) {
    //   this.question.options[data.index].score = data.grade
    // },

    upmove(index) {
      if(index != 0){
        const base = this.question.options[index-1]
        this.deleteOption(index-1,1)
        this.question.options.splice(index,0,base)
      }
    },

    downmove(index) {
      if(index != (this.question.options.length-1)){
        const base = this.question.options[index]
        this.deleteOption(index,1)
        this.question.options.splice(index+1,0,base)
      }
    },

    addFinalOption() {
      switch(this.question.type){
        case 'radio':
        case 'checkbox':
          this.question.options.push(
              {id: null,
                text: '选项', isDefault: false , description:null})
          break
        case 'score':
          this.question.options.push(
              {id: null,
                text: '选项'+(index+2), score: index+2})
          break
      }
    },

    copy(question) {
      let data = {
        questionnaireId: this.questionnaireId,
        type: question.type
      }
      axios.post('/api/edit/addQuestion',qs.stringify(data)).then(res => {
        if(res.data.code == 0) {
          const newQuestion = JSON.parse(JSON.stringify(question))
          newQuestion.id = this.getdata(res)['questionId']
          newQuestion.isSelect = false
          switch(newQuestion.type){
            case 'radio':
              newQuestion.options.forEach((option, index) => {
                option.id = null
                newQuestion.options.splice(index, 1, option)
              });
              axios.post('/api/edit/editRadio',newQuestion).then(res => {
                if(res.data.code == 0) {
                  this.questions.splice(this.questions.indexOf(question)+1, 0, newQuestion)
                  this.apiChangeOrder()
                }else {
                  console.log(res)
                }
              })
              break
            case 'checkbox':
              newQuestion.options.forEach((option, index) => {
                option.id = null
                newQuestion.options.splice(index, 1, option)
              });
              axios.post('/api/edit/editCheckBox',newQuestion).then(res => {
                if(res.data.code == 0) {
                  this.questions.splice(this.questions.indexOf(question)+1, 0, newQuestion)
                  this.apiChangeOrder()
                }else {
                  console.log(res)
                }
              })
              break
            case 'completion':
              axios.post('/api/edit/editCompletion',newQuestion).then(res => {
                if(res.data.code == 0) {
                  this.questions.splice(this.questions.indexOf(question)+1, 0, newQuestion)
                  this.apiChangeOrder()
                }else {
                  console.log(res)
                }
              })
              break
            case 'score':
              newQuestion.options.forEach((option, index) => {
                option.id = null
                newQuestion.options.splice(index, 1, option)
              });
              axios.post('api/edit/editScore',newQuestion).then(res => {
                if(res.data.code == 0) {
                  this.questions.splice(this.questions.indexOf(question)+1, 0, newQuestion)
                  this.apiChangeOrder()
                }else {
                  console.log(res)
                }
              })
              break
          }
        }else{
          console.log(res);
        }
      })
    },

    deleteQ(question) {
      this.apiDeleteQuestion(question.id, question.type)
      this.questions.splice(this.questions.indexOf(question),   1)
    },

    findIndex(question) {
      return this.questions.indexOf(question)
    },

    clearEdit() {
      this.questions.forEach((question, index) => {
        question.isSelect = false
        this.questions.splice(index, 1, question)
      });
    },

    moveup(question) {
      const index = this.findIndex(question)
      if(index > 0) {
        const base = this.questions[index-1]
        this.questions.splice(index-1, 1)
        this.questions.splice(index, 0, base)
        this.editindex = 0
      }
      this.apiChangeOrder()
    },

    movedown(question) {
      const index = this.findIndex(question)
      if(index < this.questions.length-1) {
        const base = this.questions[index]
        this.questions.splice(index, 1)
        this.questions.splice(index+1, 0, base)
        this.editindex = 0
      }
      this.apiChangeOrder()
    },

    movetop(question) {
      const index = this.findIndex(question)
      if(index > 0) {
        const base = this.questions[0]
        this.questions.splice(0, 1, question)
        this.questions.splice(index, 1, base)
        this.editindex = 0
      }
      this.apiChangeOrder()
    },

    movebottom(question) {
      const index = this.findIndex(question)
      const end = this.questions.length-1
      if(index < end) {
        const base = this.questions[index]
        this.questions.splice(index, 1, this.questions[end])
        this.questions.splice(end, 1, base)
        this.editindex = 0
      }
      this.apiChangeOrder()
    },

    addQuestion(type) {
      switch(type) {
        case '单项选择':
          this.apiAddQuestion('radio')
          break
        case '多项选择':
          this.apiAddQuestion('checkbox')
          break
        case '填空':
          this.apiAddQuestion('completion')
          break
        case '评分':
          this.apiAddQuestion('score')
          break
        case '获取地理位置信息':
          this.apiAddQuestion('completion', 'card')
          break

      }
    },

    handleDragStart(e,item){
      this.dragging = item;
    },

    handleDragEnd(e,item){
      this.dragging = null
    },

    //首先把div变成可以放置的元素，即重写dragenter/dragover
    handleDragOver(e) {
      e.dataTransfer.dropEffect = 'move'// e.dataTransfer.dropEffect="move";//在dragenter中针对放置目标来设置!
    },

    handleDragEnter(e,item){
      e.dataTransfer.effectAllowed = "move"//为需要移动的元素设置dragstart事件
      if(item === this.dragging){
        return
      }
      const newItems = [...this.questions]
      const src = newItems.indexOf(this.dragging)
      const dst = newItems.indexOf(item)

      newItems.splice(dst, 0, ...newItems.splice(src, 1))

      this.questions = newItems
      this.apiChangeOrder()
    },

    autoFill(data) {
      const length = data.max - data.min + 1
      if(length == 0) return
      this.questions[this.editindex].options = []
      for(let i = 0; i < length; i++) {
        this.questions[this.editindex].options.splice(i, 0,
            {id: null,
              text: '分数'+ (data.min+i),
              score: (data.min+i)})
      }
    },

    getmax(question) {
      console.log((question.options.length - 1));
      return question.options.length - 1

    },
  }
}
</script>

<style scoped src='assets/css/editcss/rightCreate.css'>
  /* @import url('./css/rightCreate.css'); */
</style>
